package com.gobuy.search.controller;

import com.gobuy.common.pojo.Result;
import com.gobuy.common.pojo.StatusCode;
import com.gobuy.search.service.ESManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Gaozexi on 2020/6/8 23:11
 * Step by Step  and Stand on,  You Are The Best Investment!
 */
@RestController
@RequestMapping("/es")
public class ESManageController {
    @Autowired
    private ESManagerService esManagerService;

    @GetMapping("/create")
    private Result create(){
        esManagerService.createIndexAndMapping();
        return new Result(true, StatusCode.OK,"创建商品SkuInfo索引库成功");
    }

    @GetMapping("/importAll")
    private Result importAll(){
        esManagerService.importAll();
         return new Result(true, StatusCode.OK,"已完成导入全部sku数据到SkuInfo索引库");
    }

    @GetMapping("/import/{spuId}")
    private Result importBySpuId(@PathVariable("spuId") String spuId){
        esManagerService.importDataToESBySpuId(spuId);
        return new Result(true, StatusCode.OK,"已完成导入指定的sku数据到SkuInfo索引库");
    }
}
